package com.vdf.sisconsolid.persistencemodule.dao;

import java.util.List;
import java.util.Map;

import com.vdf.sisconsolid.persistencemodule.converter.AddressConverter;
import com.vdf.sisconsolid.persistencemodule.dto.KeyValueBean;
import com.vdf.sisconsolid.persistencemodule.model.City;
import com.vdf.sisconsolid.persistencemodule.model.Neighborhood;
import com.vdf.sisconsolid.persistencemodule.model.Province;
import com.vdf.sisconsolid.persistencemodule.model.Street;

public class AddressDao extends BaseDao {

	public List<KeyValueBean> getProvinceList() {
		return AddressConverter
				.toProvinceKeyValue(listAll("SELECT p FROM Province p"));
	}

	public List<KeyValueBean> getCityList(Map<String, Object> parameters) {
		String query = "SELECT c FROM City c ";

		if (parameters.get("idProvince") != null) {
			query += "WHERE c.province.id = :idProvince";
		}
		return AddressConverter
				.toCityKeyValue(listAll(query, parameters));
	}

	public List<KeyValueBean> getNeighborhoodList(Map<String, Object> parameters) {
		String query = "SELECT n FROM Neighborhood n ";

		if (parameters.get("idCity") != null) {
			query += "WHERE n.city.id = :idCity";
		}
		return AddressConverter
				.toNeighborhoodKeyValue(listAll(query, parameters));
	}

	public List<KeyValueBean> getStreetList(Map<String, Object> parameters) {
		String query = "SELECT s FROM Street s ";

		if (parameters.get("idCity") != null) {
			query += "WHERE s.city.id = :idCity";
		}
		return AddressConverter
				.toStreetKeyValue(listAll(query, parameters));
	}

}
